package org.csu.backofficemanagersys.Response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;

import java.io.Serializable;

@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseMsg<T> implements Serializable {
    private int code;
    private String responseMsg;
    private T data;

    private ResponseMsg(int code){
        this.code = code;
    }
    private ResponseMsg(int code,String responseMsg){
        this.code = code;
        this.responseMsg = responseMsg;
    }
    private ResponseMsg(int code,String responseMsg,T data){
        this.code = code;
        this.responseMsg = responseMsg;
        this.data = data;
    }
    private ResponseMsg(int code,T data){
        this.code = code;
        this.data = data;
    }
    @JsonIgnore
    public boolean isSuccess(){
        return this.code == ResponseCode.SUCCESS.getCode();
    }

    public static <T> ResponseMsg <T> createForSuccess(){
        return new ResponseMsg<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDescription());
    }
    public static <T> ResponseMsg <T> createForSuccess(T data){
        return new ResponseMsg<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDescription(),data);
    }
    public static <T> ResponseMsg <T> createForSuccessMsg(String msg){
        return new ResponseMsg<T>(ResponseCode.SUCCESS.getCode(),msg);
    }
    public static <T> ResponseMsg <T> createForSuccess(String msg,T data){
        return new ResponseMsg<T>(ResponseCode.SUCCESS.getCode(),msg,data);
    }
    public static <T> ResponseMsg <T> createForError(){
        return new ResponseMsg<T>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDescription());
    }
    public static <T> ResponseMsg <T> createForError(String msg){
        return new ResponseMsg<T>(ResponseCode.ERROR.getCode(),msg);
    }
    public static <T> ResponseMsg <T> createForError(int code,String msg){
        return new ResponseMsg<T>(code,msg);
    }
}
